package IO流.处理流;

import org.junit.jupiter.api.Test;

import java.io.*;
import java.nio.charset.StandardCharsets;
/*
    1.InputStreamReader是Reader的子类，可以将InputStream(字节流)包装成Reader(字符流)
    2.OutputStreamWriter是Write的子类，实现将OutPutStream(字节流)包装成Writer(字符流)
    3.当处理文本数据时，如果使用字符流效率更高，并且可以有效解决中文乱码问题，所以建议将字节流成字符流
    4.可以在使用的时候指定编码格式
 */
public class codeQuestion {
    public static void main(String[] args) throws IOException {
        String filePath = "src/main/java/IO流/处理流/2.txt";
        //创建字符的转换流,InputStreamReader字节流转换成字符流，可以设置编码
        InputStreamReader bufferedReader = new InputStreamReader(new FileInputStream(filePath), StandardCharsets.UTF_8);
        char[] chars = new char[1024];
        BufferedReader bufferedReader1 = new BufferedReader(bufferedReader);
        String  temp;
        while ((temp = bufferedReader1.readLine()) != null)
            System.out.println(temp);
        bufferedReader1.close();
    }

    @Test
    public void write() throws IOException {
        String filePath = "src/main/java/IO流/处理流/2.txt";
        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream(filePath,true), StandardCharsets.UTF_8);
        BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter);
        bufferedWriter.write("43241居服ID减肥ID是");
        bufferedWriter.newLine();
        bufferedWriter.close();
    }
}
